package com.fangyang.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
    /**
     * 不用写controller访问页面
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // 访问"/",跳转到"login.html"
        registry.addViewController("/").setViewName("login");
        super.addViewControllers(registry);
    }

    /**
     * 拦截器
     */

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // addPathPatterns("/**")对所有请求都拦截 ,excludePathPatterns("/", "/user/login")排除"/"和"/user/login"
        registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**").excludePathPatterns("/", "/user/login");
        super.addInterceptors(registry);
    }

}
